package com.banana.manager.forest.service.impl.info;

import com.banana.manager.forest.dao.userandinfo.IDiseaseDao;
import com.banana.manager.forest.entity.info.DiseaseBean;
import com.banana.manager.forest.service.iinfo.IDiseaseService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
@Service
@Transactional
public class DiseaseServiceImpl implements IDiseaseService {

    @Resource
    private IDiseaseDao diseaseDao;

    @Override
    public DiseaseBean addDisease(DiseaseBean diseaseBean) {
        diseaseDao.insert(diseaseBean);
        return diseaseDao.selectById(diseaseBean.getDiseaseId());
    }

    @Override
    public DiseaseBean findOneById(Integer id) {
        return diseaseDao.selectById(id);
    }

    @Override
    public PageInfo<DiseaseBean> findBlurByPage(Integer page, String diseaseName, String diseaseSymptom) {
        QueryWrapper<DiseaseBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("disease_name","%"+diseaseName+"%");
        queryWrapper.like("disease_symptom","%"+diseaseSymptom+"%");
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(diseaseDao.selectList(queryWrapper));
    }
}
